﻿#region copyright
//Copyright 2013 Ramon Ordiales Plaza
//
//This file is part of FastMessage.
//
//    FastMessage is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    FastMessage is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with FastMessage.  If not, see <http://www.gnu.org/licenses/>.
//
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace FastMessage
{
    public class FastMessageLib
    {
        public static readonly int puerto = 9900;
        public static void SendMessage(Message msg){
            using (UdpClient udpClient = new UdpClient())
            {
                Byte[] sendBytes = Encoding.ASCII.GetBytes(msg.DataGram);
                IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), puerto);
                udpClient.Send(sendBytes, sendBytes.Length, RemoteIpEndPoint);
            }
        }
        public static string GetOrigen()
        {
            return System.Security.Principal.WindowsIdentity.GetCurrent().Name;
        }
    }
    public class Message{
        public string Origen{get;set;}
        public string Destino{get;set;}
        public string Texto{get;set;}
        public string DataGram
        {
            get
            {
                return Origen + Environment.NewLine + Destino + Environment.NewLine + Texto;
            }
        }
        public Message() { }
        public Message(string origen, string destino, string texto)
        {
            Origen = origen;
            Destino = destino;
            Texto = texto;
        }

    }
}
